package Test07;

//线程池

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
public static <u>ExecutorService</u> newCachedThreadPool()                            创建一个没有上限的线程池
public static <u>ExecutorService</u> newFixedThreadPool(int nThreads)                 创建有上限的线程池
 */
public class Test15 {
    public static void main(String[] args) {

        //1、创建线程池
        ExecutorService pool1 = Executors.newFixedThreadPool(3);

        //2、提交任务
        pool1.submit(new MyRunnable15());
        pool1.submit(new MyRunnable15());
        pool1.submit(new MyRunnable15());
        pool1.submit(new MyRunnable15());
        pool1.submit(new MyRunnable15());

        //3、销毁线程池     ---->一般不进行销毁
        //pool1.shutdown();
    }
}

class MyRunnable15 implements Runnable {

    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName() + "----" + i);
        }
    }
}
